<?php
class huishouControl extends Control {

    //显示文章列表
    function index() {
        C("debug",0);
        $db = K("arc");
        $total = $db->where("huishou=1")->count(); //获得总条数
        $page=new page($total,"10",3,1);
        $data=$db->where("huishou=1")->order("aid asc")->limit($page->limit())->all();
        $page=$page->show();
        $this->assign("page",$page);
        $this->assign("data", $data);
        $this->display();
    }

    //还原文章
    function rearc() {
        $aid = $this->_get("aid");
        if ($aid) {
            $db = M("arc");
            $data = array(); //返回客户端的数据
            if ($db->find("aid=" . $aid)) {
                $_POST=array("aid"=>$aid,'huishou'=>0);
                $db->update();
                $data['stat'] = "success";
                $data['msg'] = "";
            } else {
                $data['stat'] = "error";
                $data['msg'] = "删除文章失败,请重试";
            }
            echo json_encode($data);exit;
        }
    }

    //删除文章
    function delarc() {
        $aid = $this->_get("aid");
        if ($aid) {
            $db = M("arc");
            $data = array(); //返回客户端的数据
            if ($db->find("aid=" . $aid)) {
                $db->del($aid);
                $data['stat'] = "success";
                $data['msg'] = "";
            } else {
                $data['stat'] = "error";
                $data['msg'] = "删除文章失败,请重试";
            }
            echo json_encode($data);exit;
        }
    }

    //清空回收站
    function clearall() {
        $c=isset($_GET['aid'])?1:0;
        $aid = $this->_get("aid");
        $aid = explode(',', $aid);
        // $data['msg'] = var_dump($aid);
        // echo json_encode($data);exit;
        if ($c) {
            // $data['msg'] = $aid;
            // echo json_encode($data);exit;
            $data = array(); //返回客户端的数据
            foreach ($aid as $v) {
                $db = M("arc");
                if ($db->find("aid=" . $v)) {
                    $db->del($v);
                    $data['stat'] = "success";
                    $data['msg'] = "";
                }else {
                    $data['stat'] = "error";
                    $data['msg'] = "删除文章失败,请重试";
                }
            }
            echo json_encode($data);exit;
        }
    }



    /**
     * 向模板分配置栏目
     * @access  private
     */
    private function assignCategoryData() {
        $db = M("category");
        $result = $db->all();
        $data = Data::channel($result, "cid", "pid", 0, "", 2, "--");
        $this->assign("category", $data);
    }

}

?>
